# Be sure to restart your web server when you modify this file.

# Uncomment below to force Rails into production mode when 
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here
  
  # Skip frameworks you're not going to use (only works if using vendor/rails)
  # config.frameworks -= [ :action_web_service, :action_mailer ]

  # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
  # config.plugins = %W( exception_notification ssl_requirement )

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Force all environments to use the same logger level 
  # (by default production uses :info, the others :debug)
  # config.log_level = :debug

  # Use the database for sessions instead of the file system
  # (create the session table with 'rake db:sessions:create')
  # config.action_controller.session_store = :active_record_store

  # es necesario desde rails 2.0.2
  config.action_controller.session = {  :session_key => "_myapp_session",  :secret => "estaeslafrasesecretaquevoyaponer" }

  # Use SQL instead of Active Record's schema dumper when creating the test database.
  # This is necessary if your schema can't be completely dumped by the schema dumper, 
  # like if you have constraints or database-specific column types
  # config.active_record.schema_format = :sql

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector

  # Make Active Record use UTC-base instead of local time
  # config.active_record.default_timezone = :utc
  
  # See Rails::Configuration for more options
  
  config.action_mailer.delivery_method = :test
end

# Add new inflection rules using the following format 
# (all these examples are active by default):
# Inflector.inflections do |inflect|
#   inflect.plural /^(ox)$/i, '\1en'
#   inflect.singular /^(ox)en/i, '\1'
#   inflect.irregular 'person', 'people'
#   inflect.uncountable %w( fish sheep )
# end

# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register "application/x-mobile", :mobile


# -------------------------------------------------------------------------------------
# Include your application configuration below

# del PLUGIN acts_as_taggable_on_steroids
  TagList.delimiter = ","

  require 'scope_out'

  TEL_REGEX = /^\d[\d| |\-|\.]{6,16}\d$/
  VALID_MAIL_REGEX = /^\S+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/ix
  
  DATE_FMT = "%d.%b.%Y"
  DATETIME_FMT = "#{DATE_FMT} %H:%M hs."
  MYSQL_DATE = "%Y-%m-%d"
  MYSQL_DATETIME = "#{MYSQL_DATE} %H:%M:00"
  
  
  APP_NAME = "DESARROLLO"  

  # Utilizo mi propio log en un archivo aparte de todo los defaults de rails.
  # Para nuclear todo en el mismo logger descomentar la siguiente linea y comentar 
  # el resto. El log_level se establece arriba en el initialazer.
  # K_LOGGER = RAILS_DEFAULT_LOGGER  
  K_LOG_FILE = RAILS_ROOT+'/log/kshema.log'
  K_LOGGER = Logger.new(K_LOG_FILE,'weekly')
  K_LOGGER.formatter = Logger::Formatter.new
  K_LOGGER.formatter.datetime_format = DATETIME_FMT
  # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
  K_LOGGER.level = Logger::DEBUG
  
  SMTP_SRV = "mail.kshema.com.ar"
  SMTP_USR = "dwayne"
  SMTP_PAS = "c45p3r"

  ActionMailer::Base.logger = K_LOGGER
  ActionMailer::Base.perform_deliveries = false
  ActionMailer::Base.raise_delivery_errors = true
  ActionMailer::Base.smtp_settings = {
    :address => SMTP_SRV,
    :port => 26,
    :user_name => SMTP_USR,
    :password => SMTP_PAS,
    :authentication => :plain
  }
  
#  K_LOGGER.debug 'se ejecuta el enviroment.rb'
#  
#  # creo el scheduler con precision de 1 segundo. (chequea 1 vez por segundo, es lo mas lento posible)
#  scheduler = Rufus::Scheduler.new(:scheduler_precision => 1.0)
#  scheduler.schedule_every("10s") { K_LOGGER.debug "el scheduler funciona." }
#  scheduler.schedule_every("1h") { K_LOGGER.debug "backup internalizado en la aplicacion." }
#  scheduler.schedule_every("1d") do
#    Persona.find_alumnos(:all, :conditions=>'fecha_nacimiento not null').each do |p|
#      if (p.fecha_nacimiento and (p.fecha_nacimiento == Date.today))
#        k_mailer.deliver_happybirthday(p)
#        K_LOGGER.info "Mail enviado a #{p.nombre_completo} por su cumple."
#      end
#    end
#  end
#  scheduler.schedule_every("1d") do
#    AccountController::actualizar_coeficientes
#    K_LOGGER.debug "actualizar el coeficiente de personas segun evasiones o matriculas que se hayan hecho a futuro."
#  end
#  scheduler.schedule_every("1h"){ K_LOGGER.debug "mandar los mails que quedaron encolados por superar el limite de 200 mails x hora." }
#  
#  scheduler.start
